<?php
/**
 * Author: xin
 * Email: niuxinxin0909@163.com
 * Created at: 2020-01-29 14:42
 */

namespace common\services;

use backend\models\form\BrandForm;
use backend\models\search\OptionsSearch;
use common\models\Options;
use yii\base\Exception;

class BrandService extends Service implements BrandServiceInterface
{
    public function getSearchModel(array $options = [])
    {
        return new OptionsSearch([]);
    }

    public function getModel($id, array $options = [])
    {
        return BrandForm::findOne($id);
    }

    public function newModel(array $options = [])
    {
        $model = new BrandForm();
        $model->loadDefaultValues();
        return $model;
    }

    public function getBrandByName($name)
    {
        $model = BrandForm::findOne(["name"=>$name]);
        if( $model === null ) throw new Exception("Not exists advertisement named " . $name);
        return $model;
    }

}